package im.ok.back.controller;

import im.ok.back.common.ServerResponse;
import im.ok.back.pojo.FeedBack;
import im.ok.back.service.IFeedBackService;
import im.ok.back.vo.FeedBackQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("feedback")
public class FeedBackController {

    @Autowired
    private IFeedBackService iFeedBackService;

    @PostMapping("addFeedBack")
    public ServerResponse addFeedBack(FeedBack feedBack) {
        return iFeedBackService.add(feedBack);
    }

    @GetMapping("getList")
    public ServerResponse getList(FeedBackQuery feedBackQuery) {
        return iFeedBackService.getList(feedBackQuery);
    }

    @PostMapping("delFeedBack")
    public ServerResponse delFeedBack(String id) {
        return iFeedBackService.delete(id);
    }

    @PostMapping("import")
    @Transactional(rollbackFor = {Exception.class})
    public ServerResponse importData (@RequestParam("file")MultipartFile file) {
        return iFeedBackService.importData(file);
    }

}
